import { Effect, Reducer } from 'umi';

export interface UserModelState {
  suggest?: string;
}

export interface UserModelType {
  namespace: 'answer';
  state: UserModelState;
  effects: {
    fetch: Effect;
    fetchCurrent: Effect;
  };
  reducers: {
    saveCurrentUser: Reducer<UserModelState>;
    changeNotifyCount: Reducer<UserModelState>;
  };
}

const AnswerModel: UserModelType = {
  namespace: 'answer',

  state: {
    currentUser: {},
  },

  effects: {
    // *fetch(_, { call, put }) {
    //   const response = yield call(queryUsers);
    //   yield put({
    //     type: 'save',
    //     payload: response,
    //   });
    // },
    // *fetchCurrent({payload}, { call, put }) {
    //   console.log('payload fetchCurrent',payload);
    //   const {code,data} = yield call(queryCurrent,payload);
    //   if(code === 0){
    //     const {isLeader} = data
    //     const authority:string = isLeader ? 'leader' : 'user'
    //     localStorage.setItem('antd-pro-authority',authority)
    //     console.log('response.data.isLeader',isLeader)
    //     yield put({
    //       type: 'saveCurrentUser',
    //       payload: data,
    //     });
    //   }
    // },
  },

  reducers: {
    saveCurrentUser(state, { payload, payload: { partjobrealname } }) {
      return {
        ...state,
        currentUser: { ...payload, ...{ name: partjobrealname } } || {},
      };
    },
  },
};

export default AnswerModel;
